package com.ruoyi.hotel.controller;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.hotel.domain.bo.HmSupplyBo;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.hotel.domain.vo.HmSupplyVo;
import com.ruoyi.hotel.service.IHmSupplyService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 物资管理
 *
 * @date 2023-10-30
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/hotel/supply")
public class HmSupplyController extends BaseController {

    private final IHmSupplyService iHmSupplyService;

    /**
     * 查询物资列表
     */
    @SaCheckPermission("hotel:supply:list")
    @GetMapping("/list")
    public TableDataInfo<HmSupplyVo> list(HmSupplyBo bo, PageQuery pageQuery) {
        return iHmSupplyService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出物资列表
     */
    @SaCheckPermission("hotel:supply:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HmSupplyBo bo, HttpServletResponse response) {
        List<HmSupplyVo> list = iHmSupplyService.queryList(bo);
        ExcelUtil.exportExcel(list, "【请填写功能名称】", HmSupplyVo.class, response);
    }

    /**
     * 获取物资详细信息
     *
     * @param supplyId 主键
     */
    @SaCheckPermission("hotel:supply:query")
    @GetMapping("/{supplyId}")
    public R<HmSupplyVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long supplyId) {
        return R.ok(iHmSupplyService.queryById(supplyId));
    }

    /**
     * 新增物资
     */
    @SaCheckPermission("hotel:supply:add")
    @Log(title = "新增物资", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody HmSupplyBo bo) {
        return toAjax(iHmSupplyService.insertByBo(bo));
    }

    /**
     * 修改物资
     */
    @SaCheckPermission("hotel:supply:edit")
    @Log(title = "修改物资", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody HmSupplyBo bo) {
        return toAjax(iHmSupplyService.updateByBo(bo));
    }

    /**
     * 删除物资
     *
     * @param supplyIds 主键串
     */
    @SaCheckPermission("hotel:supply:remove")
    @Log(title = "删除物资", businessType = BusinessType.DELETE)
    @DeleteMapping("/{supplyIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] supplyIds) {
        return toAjax(iHmSupplyService.deleteWithValidByIds(Arrays.asList(supplyIds), true));
    }
}
